package com.katze.common.heart.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class HeartBeatClientHandler extends SimpleChannelInboundHandler<String> {
    private final HeartBeatClient client;

    public HeartBeatClientHandler(HeartBeatClient client){
        this.client = client;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        if ("Close".equals(msg)) {
            ctx.channel().closeFuture();
            this.client.destroy();
        }
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        this.client.reconnect();
        super.channelInactive(ctx);
    }
}
